--[[
:::::: common functions ::::::

> how to use
  the method conky_reset_state() must be invoked by the conky's 'lua_draw_hook_pre' setting

> library features

  1) dynamically change the position of an image by taking into account runtime x,y offsets to alter
     an image's original x,y coordinates

     see conky_increment_offsets()
         conky_draw_image()

  2) dynamically update ${goto x} or ${offset x} variables with an offset at runtime
                                     ${voffset y}

     see conky_increment_offsets()
         conky_add_x_offset()
         conky_add_y_offset()

  3) ...
]]

-- table to hold global variables
vars = {}

function string:split(sep)
   local sep, fields = sep or ":", {}
   local pattern = string.format("([^%s]+)", sep)
   self:gsub(pattern, function(c) fields[#fields+1] = c end)
   return fields
end

function conky_schedule_list(url)
    local rawlist = conky_parse('${curl ' .. url .. ' 60}')
    local ret = '${color4}${font3}'

    local list = rawlist:split('\n')

    for k1,v1 in ipairs(list) do
        if k1 > 1 then
            ret = ret .. '\n'
        end

        local cols = v1:split('\t')

        for k, v in ipairs(cols) do
            if k == 1 then
                ret = ret .. string.format('%-24s', v);
            end
            if k == 2 then
                ret = ret .. v;
            end
            if k == 3 then
                ret = ret .. ' ${' .. v .. '}';
            end
            if k == 4 then
                ret = ret .. string.format('%6s', v) .. ' ${color4}${font1}';
            end
            if k == 5 then
                ret = ret .. v .. '${font3}';
            end
        end
    end

    return ret
end

function conky_render_update()
end

function conky_render_reset()
end
